package com.arcsoft.face;

import java.util.Arrays;
import java.util.List;

import com.sun.jna.Pointer;
import com.sun.jna.Structure;
import com.sun.jna.ptr.IntByReference;

public class MultiFaceInfo extends Structure {
	
	
	public MRECT.ByReference faceRect;
	public IntByReference faceOriend;
	public int faceNum;
	
	
	private MRECT[] rects;
	private int[] oriends;
	
	@SuppressWarnings("rawtypes")
	@Override
	protected List getFieldOrder() {
		return Arrays.asList("faceRect","faceOriend","faceNum");
	}
	
	public MRECT[] getFaceRects() {
		if(rects == null) {
			parseData();
		}
		return rects;
	}
	
	private void parseData() {
		rects = new MRECT[faceNum];
		oriends = new int[faceNum];
		if (faceNum > 0) {
            for (int i = 0; i < faceNum; i++) {
            	rects[i] = new MRECT(new Pointer(Pointer.nativeValue(faceRect.getPointer()) + faceRect.size() * i));
            	oriends[i] = faceOriend.getPointer().getInt(i * 4);
            }
        }
	}
	
	public int[] getFaceOriends() {
		if(oriends == null) {
			parseData();
		}
		return oriends;
	}

}
